export default {
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    item: {
      type: Object
    },
    value: [String, Number, Boolean, Array, Object, Date]
  },
  data() {
    return {
      valueTmp: this.value
    }
  },
  computed: {
    _scope() {
      return (this.item && this.item.scope) || null
    }
  },
  watch: {
    value(val) {
      this.valueTmp = val
    }
  },
  methods: {
    getRef() {
      return this.$refs.formItem
    },
    handleChange(val) {
      this.$emit('update:value', val)
      if (this.item && this.item.onChange) {
        this.item.onChange(val, this._scope)
      }
    },
    clear() {
      this.$emit('update:value', null)
      if (this.item && this.item.clear) {
        this.item.clear(this._scope)
      }
    },
    blur(e) {
      if (this.item && this.item.blur) {
        this.item.blur(e, this._scope)
      }
    },
    focus(e) {
      if (this.item && this.item.focus) {
        this.item.focus(e, this._scope)
      }
    },
    expandChange(arr) {
      if (this.item && this.item.expandChange) {
        this.item.expandChange(arr, this._scope)
      }
    },
    onInput(val) {
      this.$emit('update:value', val)
      if (this.item && this.item.onChange) {
        this.item.onChange(val, this._scope)
      }
    }
  }
}
